import 'package:flutter_1800/service/webService.dart';
import 'package:flutter_1800/tools/AppUtil.dart';

import '../models/user.dart';

class ApiService extends WebService {
  static Future indexData() async {
    return WebService.get("/index");
  }

  static Future queryHomeGoods(String type) async {
    return WebService.get("/api/front/index/product/" + type.toString());
  }

  static Future preOrder(Map params) async {
    return WebService.post("/orders/pre", params);
  }

  static Future getOrder(int id) async {
    return WebService.post("/orders/get", {"id": id});
  }

  static cancelOrder(item) {
    return WebService.post("/orders/cancel", {"id": item.id});
  }

  static Future addrList() async {
    return WebService.post("/address/query", {"userid": AppUtil.user!.id});
  }

  static Future addrSave(params) async {
    return WebService.post("/address/save", params);
  }

  static Future queryOrderList(int status) async {
    return WebService.post(
        "/orders/query", {"userid": AppUtil.user!.id, "status": status});
  }

  static Future login(Map params) async {
    return WebService.post("/login", params);
  }

  static Future addCart(int goodsid, int? userid, int num, int specid,
      String specname, double specprice, String specunit) async {
    Map params = {};
    params['goodsid'] = goodsid;
    params['userid'] = userid;
    params['num'] = num;
    params['specid'] = specid;
    params['specname'] = specname;
    params['specprice'] = specprice;
    params['specunit'] = specunit;
    return WebService.post("/cart/add", params);
  }

  static Future cartList() async {
    return WebService.post("/cart/query", {"userid": AppUtil.user!.id});
  }

  static Future queryGoods(int id) async {
    return WebService.post("/queryGoods", {});
  }

  static Future goodsDetails(int id) async {
    return WebService.post("/getGoods", {"id": id});
  }

  static updateUser(User obj) {
    return WebService.post("/user/update", obj.toMap());
  }


}
